

package tables

import (
	"fmt"
	"game/game-design/loader"
	"strings"
	ministruct "sanguo/sanguo-design/src/ministruct"
)


var SkillTable *SkillTableStruct = &SkillTableStruct{}

type SkillTableStruct struct {
	loader.DesignTable[SkillCfg]
	
	skillIdIndex map[string]*SkillCfg
	
	
	
}

func (t *SkillTableStruct) FileName() string {
	return "J技能_技能一览"
}

// 从索引中获取对象，获取不到会抛异常
func (t *SkillTableStruct) GetInSkillIdIndex(
	skillId int32,
) *SkillCfg {
	key :=
		fmt.Sprint(skillId)
	
	cfg, ok := t.skillIdIndex[key]
	if !ok {
		panic("SkillTable when GetInSkillIdIndex use key not found " + key)
	}
	return cfg
}

// 从索引中查找对象，获取不到会返回null
func (t *SkillTableStruct) FindInSkillIdIndex(
	skillId int32,
) (*SkillCfg, bool) {
	key :=
		fmt.Sprint(skillId)
	
	cfg, ok := t.skillIdIndex[key]
	return cfg, ok
}

// 加载skillIdIndex索引
func (t *SkillTableStruct) loadSkillIdIndex() {
	skillIdIndex := make(map[string]*SkillCfg)
	for _, v := range t.All() {
		keys := []string {
			fmt.Sprint(v.skillId),
		}
		key := strings.Join(keys, "_")
		_, exist := skillIdIndex[key]
		if exist {
			fmt.Println(t.FileName(), " found duplicate key ", key, " in index ", "skillIdIndex")
			continue
		}
		skillIdIndex[key] = v
	}
	t.skillIdIndex = skillIdIndex
}



func (t *SkillTableStruct) LoadAutoGenerate() {
	//加载索引
	t.loadSkillIdIndex()

	
}



type SkillCfg struct {
	skillId int32 //技能ID
	name string //技能名称
	skillType int32 //技能类型
	damageType int32 //伤害类型
	instant int32 //是否瞬发
	initAllLevel int32 //是否需要初始化全等级技能逻辑
}
// 技能ID
func (c *SkillCfg) GetSkillId() int32 {
	return c.skillId
}
// 技能名称
func (c *SkillCfg) GetName() string {
	return c.name
}
// 技能类型
func (c *SkillCfg) GetSkillType() int32 {
	return c.skillType
}
// 伤害类型
func (c *SkillCfg) GetDamageType() int32 {
	return c.damageType
}
// 是否瞬发
func (c *SkillCfg) GetInstant() int32 {
	return c.instant
}
// 是否需要初始化全等级技能逻辑
func (c *SkillCfg) GetInitAllLevel() int32 {
	return c.initAllLevel
}

func SkillTableStructNoUse() {
	fmt.Println(ministruct.Cost{})
}
